<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list0';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
}
$return=array();
$tabs=array(

	array('op'=>'list0','title'=>'待审核'),
	array('op'=>'list1','title'=>'已审核'),
	array('op'=>'list2','title'=>'审核未通过'),	
);
$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'审核未通过');
//待审核
if($_RQ['op']=='list0'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='0';
	$params['ispay']='1';
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','ordersn','paytype','mid','packname','packnum','fee','ispay','status','createtime');
	$list=pdo_getslice('jy_yuyue_viporder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$user=pdo_get('jy_yuyue_user',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$item['username']=$user['name'];
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$user['viptime']=date('Y/m/d',$user['viptime']);
			$item['viptime']=$user['viptime'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'nickname','title'=>'用户昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'用户头像','type'=>'image'),
			array('name'=>'packname','title'=>'套餐类型','type'=>'radio','options'=>'packname'),
			array('name'=>'packnum','title'=>'套餐数量','type'=>'string'),
			array('name'=>'viptime','title'=>'到期时间','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'自定义表单数据'),
			array('type'=>'post','op'=>'confirm','title'=>'通过','message'=>'确认审核通过吗'),
			array('type'=>'post','op'=>'cancel','title'=>'不通过','message'=>'确认审核不通过吗'),
		)),
		'search'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string','width'=>'40'),
		)
	);
	$return['packname']=array('1'=>'包月','2'=>'包季度','3'=>'包年');
	$return['htmls']=$htmls;
	exi($return);
}
//已审核
if($_RQ['op']=='list1'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='1';
	$params['ispay']='1';
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','ordersn','paytype','mid','packname','packnum','fee','ispay','status','createtime');
	$list=pdo_getslice('jy_yuyue_viporder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$user=pdo_get('jy_yuyue_user',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$item['username']=$user['name'];
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$user['viptime']=date('Y/m/d',$user['viptime']);
			$item['viptime']=$user['viptime'];
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'nickname','title'=>'用户昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'用户头像','type'=>'image'),
			array('name'=>'packname','title'=>'套餐类型','type'=>'radio','options'=>'packname'),
			array('name'=>'packnum','title'=>'套餐数量','type'=>'string'),
			array('name'=>'viptime','title'=>'到期时间','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'自定义表单数据'),
		)),
		'search'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string','width'=>'40'),
		)
	);
	$return['packname']=array('1'=>'包月','2'=>'包季度','3'=>'包年');
	$return['htmls']=$htmls;
	exi($return);
}
//不通过
if($_RQ['op']=='list2'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='2';
	$params['ispay']='1';
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','ordersn','paytype','mid','packname','packnum','fee','ispay','status','createtime');
	$list=pdo_getslice('jy_yuyue_viporder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$user=pdo_get('jy_yuyue_user',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$item['username']=$user['name'];
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$user['viptime']=date('Y/m/d',$user['viptime']);
			$item['viptime']=$user['viptime'];
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'nickname','title'=>'用户昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'用户头像','type'=>'image'),
			array('name'=>'packname','title'=>'套餐类型','type'=>'radio','options'=>'packname'),
			array('name'=>'packnum','title'=>'套餐数量','type'=>'string'),
			array('name'=>'viptime','title'=>'到期时间','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'自定义表单数据'),
		)),
		'search'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string','width'=>'40'),
		)
	);
	$return['packname']=array('1'=>'包月','2'=>'包季度','3'=>'包年');
	$return['htmls']=$htmls;
	exi($return);
}

//确认操作
if($_RQ['op']=='confirm'){
	if($_RQ['id']){
	
		pdo_update('jy_yuyue_viporder',array('status'=>'1'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('审核已通过！');
}
//取消操作
if($_RQ['op']=='cancel'){
	if($_RQ['id']){
	
		pdo_update('jy_yuyue_viporder',array('status'=>'2'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('已驳回！');
}

if($_RQ['op']=='look'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yuyue_viporder',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		exi('请选择激活申请','error');
	}
	
	$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('avatar','nickname'));
	$item['avatar'] = $member['avatar'];
	$item['nickname'] = $member['nickname'];
	$item['data']=pdo_getall('jy_yuyue_vip_data',array('uniacid'=>$_SESSION['uniacid'],'order_id'=>$item['id']));
	$formtypes=get_form_types();
	foreach($item['data'] as &$v){
		if($v['type']==5 && $v['data']){
			$v['data'] = explode(";", $v['data']);
			foreach($v['data'] as $k=>&$i){
				if(empty($v['data'][$k])){
					unset($v['data'][$k]);
				}
			}
		}
		
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'tabs'=>array(
			array('op'=>'list0','title'=>'返回待审核列表'),
		),
		'desc'=>'自定义表单信息',
		'look'=>array(
				array('type'=>'string','title'=>'用户名称','name'=>'nickname','help'=>''),
				array('type'=>'image','title'=>'用户头像','name'=>'avatar','help'=>''),
				array(
						'title'=>'表单详情',
						'type'=>'array',
						'name'=>'data',
						'list'=>array(
							array('type'=>'string','name'=>'title','title'=>'表单标题'),	
							array('type'=>'labelarray','name'=>'data','title'=>'表单内容'),	
						),
				)
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

